<template>
    <div class="sidebar">
        <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
                 text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                                <template slot="title">{{ subItem.title }}</template>
                                <el-menu-item v-for="(threeItem,i) in subItem.subs" :key="i" :index="threeItem.index">
                                    {{ threeItem.title }}
                                </el-menu-item>
                            </el-submenu>
                            <el-menu-item v-else :index="subItem.index" :key="subItem.index">
                                {{ subItem.title }}
                            </el-menu-item>
                        </template>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
    import bus from '@/api/bus';

    export default {
        data() {
            return {
                collapse: false,
              items: [
                {
                  icon: 'el-icon-lx-home',
                  index: '1',
                  title: '系统管理',
                  subs: [
                    {
                      index: 'ControlPanel',
                      title: '控制面板'
                    },
                    {
                      index: 'FileController',
                      title: '文件管理'
                    },
                    {
                      index: 'UserManger',
                      title: '用户管理'
                    },
                    {
                      index: 'DepartmentManger',
                      title: '部门管理'
                    }, {
                      index: 'RoleManger',
                      title: '角色管理'
                    },
                    {
                      index: 'AuthorityManger',
                      title: '权限管理'
                    },
                    {
                      index: 'IconManager',
                      title: '图标管理'
                    },
                  ]
                },
                {
                  icon: 'el-icon-lx-cascades',
                  index: '2',
                  title: '业务管理',
                  subs: [
                    {
                      index: 'ProductGo',
                      title: '物资去处'
                    },
                    {
                      index: 'ProductRecord',
                      title: '入库记录'
                    },
                    {
                      index: 'ProductInfo',
                      title: '物资资料'
                    },
                    {
                      index: 'ProductCategory',
                      title: '物资类别'
                    },
                    {
                      index: 'Productource',
                      title: '物资来源'
                    }, {
                      index: 'ReleaseRecord',
                      title: '发放记录'
                    },
                    {
                      index: 'ProductStock',
                      title: '物资库存'
                    }
                  ]
                },
                {
                  icon: 'el-icon-lx-copy',
                  index: 'page3',
                  title: 'page3'
                },
                {
                  icon: 'el-icon-lx-calendar',
                  index: '3',
                  title: '系统',
                  subs: [
                    {
                      index: '403',
                      title: '403'
                    },
                    {
                      index: '404',
                      title: '404'
                    }
                  ]
                },
              ]
            }
        },
        computed: {
            onRoutes() {
                return this.$route.path.replace('/', '');
            }
        },
        created() {
            //const role = localStorage.getItem('ms_role');
            // 通过 Event Bus 进行组件间通信，来折叠侧边栏
            bus.$on('collapse', msg => {
                this.collapse = msg;
            })
        }
    }
</script>

<style scoped>
    .sidebar {
        display: block;
        position: absolute;
        left: 0;
        top: 70px;
        bottom: 0;
        overflow-y: scroll;
    }

    .sidebar::-webkit-scrollbar {
        width: 0;
    }

    .sidebar-el-menu:not(.el-menu--collapse) {
        width: 250px;
    }

    .sidebar > ul {
        height: 100%;
    }
</style>
